<template>
  <section class="main">
    <scroll class="scroll">
    <div class="list" v-show="addresses">
      <div class="item" v-for="(item, index) in addresses" :key="index">
        <p class="address">
          {{ item.address_detail }}
        </p>
        <p>
          {{ item.phone }}
        </p>
        <span
          class="cross"
          v-show="isShow"
          @click="handleDeleteAddresses(item.id)"
          >X</span
        >
      </div>
    </div>
    <div class="newly-added" @click="handleSkipAdd">
      <span class="left">新增地址</span>
      <span class="right"></span>
    </div>
    </scroll>
  </section>
</template>

<script>
import Scroll from 'components/common/betterScroll/Scroll'

import { SET_ADDRESSES } from "store/mutations.type";

import { mapGetters } from "vuex";
export default {
  data() {
    return {
      isShow: false,
    };
  },
  computed: {
    ...mapGetters(["addresses"]),
  },
  created() {
    this.addresses.message ? this.$store.commit(SET_ADDRESSES, []) : "";
  },
  mounted() {
    this.$bus.$on("handleSwitchText", (res) => {
      this.isShow = !this.isShow;
    });
  },
  methods: {
    handleSkipAdd() {
      this.$router.push("/profile/info/address/add");
    },
    handleDeleteAddresses(id) {
      this.$bus.$emit("handleDeleteAddresses", id);
    },
  },
  components: {
    Scroll
  }
};
</script>
<style lang="less" scoped>
.main {
  height: calc(100% - 44px);
  margin-top: 10px;
  border-top: 1px solid #e2e2e2;
  .scroll {
    height: 100%;
    overflow: hidden;
  }
  .list {
    margin-bottom: 10px;
    background-color: #fff;
    font-size: 14px;
    color: #333333;
    .item {
      position: relative;
      padding: 15px 10px;
      border-bottom: 1px solid #ededed;
      .address {
        margin-bottom: 6px;
      }
      .cross {
        position: absolute;
        top: 50%;
        right: 15px;
        color: #b39999;
        transform: translateY(-50%);
      }
    }
    & .item:nth-child(1) {
      background-color: #fff8c3;
    }
  }
  .newly-added {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-top: 1px solid #e2e2e2;
    border-bottom: 1px solid #e2e2e2;
    background-color: #fff;
    .right {
      width: 6px;
      height: 6px;
      border-top: 2px solid #dddddd;
      border-right: 2px solid #dddddd;
      transform: rotate(45deg);
    }
  }
}
</style>